package com.zmn.plat.utils.bean;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2021/3/23 19:01
 **/
public class PageUtils {
    /**
    * 描述：内存分页
    * @param result
    * @param pageNum
    * @param pageSize
    * @author tanbiao
    * @since 2021/3/23 19:02
    * @return java.util.List<U>
    * @modifier      
    */
    public static <U> List<U> listPage(List<U> result, Integer pageNum, Integer pageSize) {
        List<U> returnList = new ArrayList<>();
        Integer from = (pageNum - 1) * pageSize;
        Integer to = pageNum * pageSize;
        if (from > result.size()) {
            return Lists.newArrayList();
        }
        if (result.size() > to) {
            returnList = result.subList(from, to);
        } else {
            returnList = result.subList(from, result.size());
        }
        return returnList;
    }
}
